package tyx.study.jsp.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import tyx.study.jsp.javabean.Emp;
import tyx.study.jsp.service.IEmpService;
import tyx.study.jsp.service.impl.EmpServiceImp;

public class AllEmpServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String pageStr=req.getParameter("page");
		String pageNumStr=req.getParameter("pageNum");
		int page=pageStr==null?1:Integer.parseInt(pageStr);
		int pageNum=pageNumStr==null?2:Integer.parseInt(pageNumStr);
		IEmpService empService=new EmpServiceImp();
		List<Emp> list = empService.allEmps(page,pageNum);
		req.setAttribute("empList", list);
		req.setAttribute("page", page);
		req.setAttribute("pages",empService.getPages(pageNum));
		req.setAttribute("pageNum", pageNum);
		req.getRequestDispatcher("allEmp.jsp").forward(req, resp);}
		
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
